local skel = fk.CreateSkill {
  name = "emo__lingfeng",
}

Fk:loadTranslationTable{
  ["emo__lingfeng"] = "聆风",
  [":emo__lingfeng"] = "每轮结束时，你获得X张指定花色的牌，当你使用不为此花色的牌时，弃置以此法获得的牌（X为本技能发动次数）。",

  ["@@emo__lingfeng-inhand"] = "聆风",
  ["#emo__lingfeng-choice"] = "聆风：选择1种花色，你获得此花色的牌",
}

skel:addEffect(fk.RoundEnd, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = room:askToChoice(player, {
      choices = {"log_spade", "log_heart", "log_club", "log_diamond"}, skill_name = skel.name
    })
    local x = player:usedSkillTimes(skel.name, Player.HistoryGame)
    local suit = choice:sub(5)
    local ids = room:getCardsFromPileByRule(".|.|" .. suit, x, "allPiles")
    if #ids > 0 then
      room:obtainCard(player, ids, false, fk.ReasonJustMove, player, skel.name, {"@@emo__lingfeng-inhand", suit})
    end
  end,
})

skel:addEffect(fk.CardUsing, {
  anim_type = "defensive",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    if target == player and not player.dead then
      local ids = table.filter(player:getCardIds("h"), function (id)
        local mark = Fk:getCardById(id):getMark("@@emo__lingfeng-inhand")
        return mark ~= 0 and mark ~= data.card:getSuitString()
      end)
      if #ids > 0 then
        event:setCostData(self, {cards = ids})
        return true
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(event:getCostData(self).cards, skel.name, player, player)
  end,
})

return skel
